home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Pararena 1.3 / source / Parts ƒ / Guts.p < prev    next >
Encoding:
Text File  |  1991-05-18  |  24.2 KB  |  988 lines  |  [TEXT/PJMM]

  1. unit Guts;
  2.  
  3. interface
  4.     uses
  5.         Sound, Globals, Unlock, Utilities;
  6.  
  7.     procedure ResetArrows;
  8.     procedure WheresMouse;
  9.     procedure NewPlayerPosition;
  10.     function FollowDiagonally (hereX, hereZ, thereX, thereZ: LongInt): Integer;
  11.     function RunTheGoal (hereX, hereZ, speedX, speedZ: LongInt; direction: Integer): Integer;
  12.     procedure NewOpponentPosition;
  13.     procedure NewBallPosition;
  14.     procedure BallInTransit;
  15.  
  16. implementation
  17.  
  18. {=================================}
  19.  
  20.     procedure TogglePlayerArrow;
  21.         var
  22.             srcRect, dstRect: Rect;
  23.     begin
  24.         SetRect(srcRect, 422, 169, 446, 204);
  25.         SetRect(dstRect, 57, 0, 91, 35);
  26.         CopyBits(offPlayerMap, mainWndo^.portBits, srcRect, dstRect, srcXOr, nil);
  27.     end;
  28.  
  29. {=================================}
  30.  
  31.     procedure ToggleOpponentArrow;
  32.         var
  33.             srcRect, dstRect: Rect;
  34.     begin
  35.         SetRect(srcRect, 422, 205, 446, 240);
  36.         SetRect(dstRect, 425, 0, 449, 35);
  37.         CopyBits(offPlayerMap, mainWndo^.portBits, srcRect, dstRect, srcXOr, nil);
  38.     end;
  39.  
  40. {=================================}
  41.  
  42.     procedure ResetArrows;
  43.         var
  44.             dstRect: Rect;
  45.     begin
  46.         SetRect(dstRect, 57, 0, 91, 35);
  47.         CopyBits(offVirginMap, mainWndo^.portBits, dstRect, dstRect, srcCopy, nil);
  48.         SetRect(dstRect, 425, 0, 449, 35);
  49.         CopyBits(offVirginMap, mainWndo^.portBits, dstRect, dstRect, srcCopy, nil);
  50.     end;
  51.  
  52. {=================================}
  53.  
  54.     procedure WheresMouse;
  55.         var
  56.             nontant, which: Integer;
  57.             mousePt: Point;
  58.     begin
  59.         if ((Button) and (not lastButton)) then
  60.             clicked := TRUE;
  61.         lastButton := Button;
  62.  
  63.         nontant := 0;
  64.         GetMouse(mousePt);
  65.         if (mousePt.h > (340 + rightOffset)) then
  66.             nontant := 6
  67.         else if (mousePt.h < (170 + rightOffset)) then
  68.             nontant := 0
  69.         else
  70.             nontant := 3;
  71.         if (mousePt.v > (228 + downOffset)) then
  72.             nontant := nontant + 2
  73.         else if (mousePt.v < (114 + downOffset)) then
  74.             nontant := nontant + 0
  75.         else
  76.             nontant := nontant + 1;
  77.         which := nontantTable[nontant];
  78.         player.mode := which;
  79.         SetCursor(cursorArray[which]^^);
  80.     end;
  81.  
  82. {=================================}
  83.  
  84.     procedure NewPlayerPosition;
  85.         var
  86.             field1, field2, forceX, forceZ: Integer;
  87.  
  88. {-------------------------}
  89.  
  90.         procedure DoGoalSlam;
  91.         begin
  92.             with player do
  93.                 begin
  94.                     if forceX = 10000 then
  95.                         begin
  96.                             if ((velZ < 0) and (velX < 0)) then
  97.                                 begin
  98.                                     if (soundArray[5]) then
  99.                                         DoTheSound('ricochet', lowPriority);
  100.                                     forceX := velX div 4;
  101.                                     velX := -velZ div 4;
  102.                                     velZ := -forceX;
  103.                                     Exit(DoGoalSlam);
  104.                                 end;
  105.                             if ((-velZ > velX) and (velZ < 0) and (velX > 0)) then
  106.                                 begin
  107.                                     if (soundArray[5]) then
  108.                                         DoTheSound('ricochet', lowPriority);
  109.                                     forceX := velX div 4;
  110.                                     velX := -velZ div 4;
  111.                                     velZ := -forceX;
  112.                                     Exit(DoGoalSlam);
  113.                                 end;
  114.                             if ((-velX > velZ) and (velZ > 0) and (velX < 0)) then
  115.                                 begin
  116.                                     if (soundArray[5]) then
  117.                                         DoTheSound('ricochet', lowPriority);
  118.                                     forceX := velX div 4;
  119.                                     velX := -velZ div 4;
  120.                                     velZ := -forceX;
  121.                                 end;
  122.                         end
  123.                     else
  124.                         begin
  125.                             if ((velZ < 0) and (velX > 0)) then
  126.                                 begin
  127.                                     if (soundArray[5]) then
  128.                                         DoTheSound('ricochet', lowPriority);
  129.                                     forceX := velX div 4;
  130.                                     velX := velZ div 4;
  131.                                     velZ := forceX;
  132.                                     Exit(DoGoalSlam);
  133.                                 end;
  134.                             if ((velZ < velX) and (velZ < 0) and (velX < 0)) then
  135.                                 begin
  136.                                     if (soundArray[5]) then
  137.                                         DoTheSound('ricochet', lowPriority);
  138.                                     forceX := velX div 4;
  139.                                     velX := velZ div 4;
  140.                                     velZ := forceX;
  141.                                     Exit(DoGoalSlam);
  142.                                 end;
  143.                             if ((velX > velZ) and (velZ > 0) and (velX > 0)) then
  144.                                 begin
  145.                                     if (soundArray[5]) then
  146.                                         DoTheSound('ricochet', lowPriority);
  147.                                     forceX := velX div 4;
  148.                                     velX := velZ div 4;
  149.                                     velZ := forceX;
  150.                                 end;
  151.                         end;
  152.                 end;
  153.         end;
  154.  
  155. {-------------------------}
  156.  
  157.     begin
  158.         with player do
  159.             begin
  160.                 forceX := forceTable[posX div 1000, posZ div 1000, 0];
  161.                 forceZ := forceTable[posX div 1000, posZ div 1000, 1];
  162.                 if ((forceX = 10000) or (forceX = 11000)) then
  163.                     DoGoalSlam
  164.                 else if (forceX < 10000) then
  165.                     begin
  166.                         velX := velX * frictNum div frictDen + forceX + mouseForce[mode, 0];
  167.                         velZ := velZ * frictNum div frictDen + forceZ + mouseForce[mode, 1];
  168.                     end;
  169.                 posX := posX + velX;
  170.                 posZ := posZ + velZ;
  171.                 screenH := centerH + posX div 100;
  172.                 field1 := ABS(posX div 300);
  173.                 field2 := posZ div 300;
  174.                 if ((field1 < 81) and (ABS(field2) < 81)) then
  175.                     begin
  176.                         HLock(Handle(vertTable));
  177.                         screenV := vertTable^^.data[field1, field2] + 20;
  178.                         HUnlock(Handle(vertTable));
  179.                     end
  180.                 else
  181.                     begin
  182.                         if (ball.mode = playerHasBall) then
  183.                             ResetArrows;
  184.                         PlayerOutOfArena;
  185.                     end;
  186.                 if (screenV < 0) then
  187.                     begin
  188.                         if (ball.mode = playerHasBall) then
  189.                             ResetArrows;
  190.                         PlayerOutOfArena;
  191.                     end;
  192.                 SetRect(dest, screenH - 16, screenV - 47, screenH + 16, screenV);
  193.             end;
  194.     end;
  195.  
  196. {=================================}
  197.  
  198.     function FollowDiagonally;
  199.         const
  200.             edge = 12000;
  201.         var
  202.             displaceX, displaceZ: LongInt;
  203.  
  204. {-------------------------}
  205.  
  206.         procedure FleeTheEdge;
  207.         begin
  208.             if (hereX > edge) then
  209.                 begin
  210.                     if (hereZ > 0) then
  211.                         FollowDiagonally := northWest
  212.                     else
  213.                         FollowDiagonally := southWest;
  214.                     Exit(FleeTheEdge);
  215.                 end;
  216.             if (hereX < -edge) then
  217.                 begin
  218.                     if (hereZ > 0) then
  219.                         FollowDiagonally := northEast
  220.                     else
  221.                         FollowDiagonally := southEast;
  222.                     Exit(FleeTheEdge);
  223.                 end;
  224.             if (hereZ > edge) then
  225.                 begin
  226.                     if (hereX > 0) then
  227.                         FollowDiagonally := northWest
  228.                     else
  229.                         FollowDiagonally := northEast;
  230.                     Exit(FleeTheEdge);
  231.                 end;
  232.             if (hereZ < -edge) then
  233.                 begin
  234.                     if (hereX > 0) then
  235.                         FollowDiagonally := southWest
  236.                     else
  237.                         FollowDiagonally := southEast;
  238.                 end;
  239.         end;
  240.  
  241. {-------------------------}
  242.  
  243.     begin
  244.         displaceX := thereX - hereX;
  245.         displaceZ := thereZ - hereZ;
  246.         if (displaceX > 0) then
  247.             begin
  248.                 if (displaceZ > 0) then
  249.                     FollowDiagonally := southEast
  250.                 else
  251.                     FollowDiagonally := northEast;
  252.             end
  253.         else
  254.             begin
  255.                 if (displaceZ > 0) then
  256.                     FollowDiagonally := southWest
  257.                 else
  258.                     FollowDiagonally := northWest;
  259.             end;
  260.         if ((ABS(hereX) > edge) or (ABS(hereZ) > edge)) then        {Getting near the edge}
  261.             FleeTheEdge;
  262.     end;
  263.  
  264. {=================================}
  265.  
  266.     function RunTheGoal;
  267.     begin
  268.         RunTheGoal := direction;
  269.         if (direction = northEast) then
  270.             begin
  271.                 if ((hereZ < -16000) and (hereX > 16000)) then
  272.                     begin
  273.                         opponentDropping := TRUE;
  274.                         RunTheGoal := west;
  275.                     end
  276.                 else
  277.                     begin
  278.                         if (speedZ > 0) or (hereZ < -16000) then    {was 12000}
  279.                             RunTheGoal := southWest;
  280.                     end;
  281.             end
  282.         else if (direction = southWest) then
  283.             begin
  284.                 if ((speedZ < 0) or (hereZ > 6000)) then        {was 8000}
  285.                     RunTheGoal := northEast;
  286.             end
  287.         else        {Not facing along diagonal}
  288.             begin
  289.                 RunTheGoal := northEast;
  290.             end;
  291.     end;
  292.  
  293. {=================================}
  294.  
  295.     procedure MaraDecides;
  296.         var
  297.             newDir: Integer;
  298.     begin
  299.         with opponent do
  300.             begin
  301.                 newDir := mode;
  302.                 case ball.mode of
  303.                     nooneHasBall: 
  304.                         begin
  305.                             if (mad) then
  306.                                 newDir := FollowDiagonally(posX, posZ, player.posX, player.posZ)
  307.                             else
  308.                                 begin
  309.                                     if (DoRandom(100) = 0) then
  310.                                         mad := TRUE;
  311.                                     newDir := FollowDiagonally(posX, posZ, ball.posX, ball.posZ);
  312.                                     mode := newDir;
  313.                                 end;
  314.                             opponentWants := TRUE;
  315.                             opponentDropping := FALSE;
  316.                         end;
  317.                     playerHasBall: 
  318.                         begin
  319.                             newDir := FollowDiagonally(posX, posZ, ball.posX, ball.posZ);
  320.                         end;
  321.                     opponentHasBall: 
  322.                         begin
  323.                             newDir := RunTheGoal(posX, posZ, velX, velZ, mode);
  324.                         end;
  325.                     otherwise
  326.                         begin
  327.                         end;
  328.                 end;    {case}
  329.                 mode := newDir;
  330.             end;        {with opponent}
  331.     end;
  332.  
  333. {=================================}
  334.  
  335.     procedure OttoDecides;
  336.         var
  337.             newDir: Integer;
  338.     begin
  339.         with opponent do
  340.             begin
  341.                 newDir := mode;
  342.                 case ball.mode of
  343.                     nooneHasBall: 
  344.                         begin
  345.                             newDir := FollowDiagonally(posX, posZ, ball.posX, ball.posZ);
  346.                             opponentWants := TRUE;
  347.                             opponentDropping := FALSE;
  348.                         end;
  349.                     playerHasBall: 
  350.                         begin
  351.                             newDir := FollowDiagonally(posX, posZ, ball.posX - 5000, ball.posZ - 5000);
  352.                         end;
  353.                     opponentHasBall: 
  354.                         begin
  355.                             newDir := RunTheGoal(posX, posZ, velX, velZ, mode);
  356.                         end;
  357.                     otherwise
  358.                         begin
  359.                         end;
  360.                 end;    {case}
  361.                 mode := newDir;
  362.             end;        {with opponent}
  363.     end;
  364.  
  365. {=================================}
  366.  
  367.     procedure GeorgeDecides;
  368.         var
  369.             newDir: Integer;
  370.     begin
  371.         with opponent do
  372.             begin
  373.                 newDir := mode;
  374.                 case ball.mode of
  375.                     nooneHasBall: 
  376.                         begin
  377.                             newDir := FollowDiagonally(posX, posZ, ball.posX, ball.posZ);
  378.                             opponentWants := TRUE;
  379.                             if (DoRandom(5) = 0) then
  380.                                 opponentWants := FALSE;
  381.                             opponentDropping := FALSE;
  382.                         end;
  383.                     playerHasBall: 
  384.                         begin
  385.                             newDir := FollowDiagonally(posX, posZ, ball.posX - 9000, ball.posZ - 9000);
  386.                         end;
  387.                     opponentHasBall: 
  388.                         begin
  389.                             newDir := RunTheGoal(posX, posZ, velX, velZ, mode);
  390.                         end;
  391.                     otherwise
  392.                         begin
  393.                         end;
  394.                 end;    {case}
  395.                 mode := newDir;
  396.             end;        {with opponent}
  397.     end;
  398.  
  399. {=================================}
  400.  
  401.     procedure ClaireDecides;
  402.         var
  403.             newDir: Integer;
  404.     begin
  405.         with opponent do
  406.             begin
  407.                 newDir := mode;
  408.                 case ball.mode of
  409.                     nooneHasBall: 
  410.                         begin
  411.                             if (mad) then
  412.                                 newDir := FollowDiagonally(posX, posZ, player.posX, player.posZ)
  413.                             else
  414.                                 begin
  415.                                     if (DoRandom(400) = 0) then
  416.                                         mad := TRUE;
  417.                                     newDir := FollowDiagonally(posX, posZ, ball.posX, ball.posZ);
  418.                                 end;
  419.                             opponentWants := TRUE;
  420.                             opponentDropping := FALSE;
  421.                         end;
  422.                     playerHasBall: 
  423.                         begin
  424.                             newDir := player.mode;
  425.                         end;
  426.                     opponentHasBall: 
  427.                         begin
  428.                             newDir := RunTheGoal(posX, posZ, velX, velZ, mode);
  429.                         end;
  430.                     otherwise
  431.                         begin
  432.                         end;
  433.                 end;    {case}
  434.                 mode := newDir;
  435.             end;        {with opponent}
  436.     end;
  437.  
  438. {=================================}
  439.  
  440.     procedure NewOpponentPosition;
  441.         var
  442.             field1, field2, forceX, forceZ: Integer;
  443.  
  444. {-------------------------}
  445.  
  446.         procedure HumansCollide;
  447.             var
  448.                 tempX, tempZ: LongInt;
  449.         begin
  450.             if (soundArray[5]) then
  451.                 DoTheSound('crash', lowPriority);
  452.             mad := FALSE;
  453.             with opponent do
  454.                 begin
  455.                     tempX := velX;
  456.                     tempZ := velZ;
  457.                     velX := player.velX * denominator div numerator;
  458.                     velZ := player.velZ * denominator div numerator;
  459.                 end;
  460.             with player do
  461.                 begin
  462.                     velX := tempX * numerator div denominator;
  463.                     velZ := tempZ * numerator div denominator;
  464.                 end;
  465.             with opponent do
  466.                 begin
  467.                     if (velX = 0) then
  468.                         velX := -10;
  469.                     repeat
  470.                         posX := posX + velX;
  471.                         posZ := posZ + velZ;
  472.                         player.posX := player.posX + player.velX;
  473.                         player.posZ := player.posZ + player.velZ;
  474.                     until ((ABS(posX - player.posX) > 2500) or (ABS(posZ - player.posZ) > 2500));
  475.                 end;
  476.         end;
  477.  
  478. {-------------------------}
  479.  
  480.         procedure OpponentGoalSlams;
  481.         begin
  482.             with opponent do
  483.                 begin
  484.                     if forceX = 10000 then
  485.                         begin
  486.                             if ((velZ < 0) and (velX < 0)) then
  487.                                 begin
  488.                                     if (soundArray[5]) then
  489.                                         DoTheSound('ricochet', lowPriority);
  490.                                     forceX := velX div 4;
  491.                                     velX := -velZ div 4;
  492.                                     velZ := -forceX;
  493.                                     Exit(OpponentGoalSlams);
  494.                                 end;
  495.                             if ((-velZ > velX) and (velZ < 0) and (velX > 0)) then
  496.                                 begin
  497.                                     if (soundArray[5]) then
  498.                                         DoTheSound('ricochet', lowPriority);
  499.                                     forceX := velX div 4;
  500.                                     velX := -velZ div 4;
  501.                                     velZ := -forceX;
  502.                                     Exit(OpponentGoalSlams);
  503.                                 end;
  504.                             if ((-velX > velZ) and (velZ > 0) and (velX < 0)) then
  505.                                 begin
  506.                                     if (soundArray[5]) then
  507.                                         DoTheSound('ricochet', lowPriority);
  508.                                     forceX := velX div 4;
  509.                                     velX := -velZ div 4;
  510.                                     velZ := -forceX;
  511.                                 end;
  512.                         end
  513.                     else
  514.                         begin
  515.                             if ((velZ < 0) and (velX > 0)) then
  516.                                 begin
  517.                                     if (soundArray[5]) then
  518.                                         DoTheSound('ricochet', lowPriority);
  519.                                     forceX := velX div 4;
  520.                                     velX := velZ div 4;
  521.                                     velZ := forceX;
  522.                                     Exit(OpponentGoalSlams);
  523.                                 end;
  524.                             if ((velZ < velX) and (velZ < 0) and (velX < 0)) then
  525.                                 begin
  526.                                     if (soundArray[5]) then
  527.                                         DoTheSound('ricochet', lowPriority);
  528.                                     forceX := velX div 4;
  529.                                     velX := velZ div 4;
  530.                                     velZ := forceX;
  531.                                     Exit(OpponentGoalSlams);
  532.                                 end;
  533.                             if ((velX > velZ) and (velZ > 0) and (velX > 0)) then
  534.                                 begin
  535.                                     if (soundArray[5]) then
  536.                                         DoTheSound('ricochet', lowPriority);
  537.                                     forceX := velX div 4;
  538.                                     velX := velZ div 4;
  539.                                     velZ := forceX;
  540.                                 end;
  541.                         end;
  542.                 end;
  543.         end;
  544.  
  545. {-------------------------}
  546.  
  547.     begin
  548.         case whichOpponent of
  549.             mara: 
  550.                 MaraDecides;
  551.             otto: 
  552.                 OttoDecides;
  553.             george: 
  554.                 GeorgeDecides;
  555.             claire: 
  556.                 ClaireDecides;
  557.             otherwise
  558.                 begin
  559.                 end;
  560.         end;        {case}
  561.  
  562.         with opponent do
  563.             begin
  564.                 forceX := forceTable[posX div 1000, posZ div 1000, 0];
  565.                 forceZ := forceTable[posX div 1000, posZ div 1000, 1];
  566.                 if ((ABS(posX - player.posX) < 2500) and (ABS(posZ - player.posZ) < 2500) and (player.timeKeeper > -1)) then
  567.                     HumansCollide;
  568.                 if ((forceX = 10000) or (forceX = 11000)) then
  569.                     OpponentGoalSlams
  570.                 else if (forceX < 10000) then
  571.                     begin
  572.                         velX := velX * frictNum div frictDen + forceX + mouseForce[mode, 0];
  573.                         velZ := velZ * frictNum div frictDen + forceZ + mouseForce[mode, 1];
  574.                     end;
  575.                 posX := posX + velX;
  576.                 posZ := posZ + velZ;
  577.                 screenH := centerH + posX div 100;
  578.                 field1 := ABS(posX div 300);
  579.                 field2 := posZ div 300;
  580.                 if ((field1 < 81) and (ABS(field2) < 81)) then
  581.                     begin
  582.                         HLock(Handle(vertTable));
  583.                         screenV := vertTable^^.data[field1, field2] + 20;
  584.                         HUnlock(Handle(vertTable));
  585.                     end
  586.                 else
  587.                     begin
  588.                         if (ball.mode = opponentHasBall) then
  589.                             ResetArrows;
  590.                         OpponentOutOfArena;
  591.                     end;
  592.                 if (screenV < 0) then
  593.                     begin
  594.                         if (ball.mode = opponentHasBall) then
  595.                             ResetArrows;
  596.                         OpponentOutOfArena;
  597.                     end;
  598.                 SetRect(dest, screenH - 16, screenV - 47, screenH + 16, screenV);
  599.             end;
  600.         if (ball.timeKeeper > 290) then
  601.             opponentDropping := TRUE;
  602.     end;
  603.  
  604.  
  605. {=================================}
  606.  
  607.     procedure NewBallPosition;
  608.  
  609. {-------------------------}
  610.  
  611.         procedure PlayerCapture;
  612.         begin
  613.             tileToggle := 0;
  614.             tileLit := 0;
  615.             TogglePlayerArrow;
  616.             with ball do
  617.                 begin
  618.                     player.velX := player.velX + velX * 2 div 3;
  619.                     player.velZ := player.velZ + velZ * 2 div 3;
  620.                     velX := player.velX;
  621.                     velZ := player.velZ;
  622.                     ballJustHit := TRUE;
  623.                     mode := playerHasBall;
  624.                     timeKeeper := 1;
  625.                     player.carryMode := carrying;
  626.                     CopyBits(offVirginMap, offLoadMap, oldDest, oldDest, srcCopy, nil);
  627.                     CopyBits(offVirginMap, mainWndo^.portBits, oldDest, oldDest, srcCopy, wholeRgn);
  628.                     if (soundArray[5]) then
  629.                         DoTheSound(ballCatches[0], highPriority);
  630.                 end;
  631.         end;
  632.  
  633. {-------------------------}
  634.  
  635.         procedure OpponentCapture;
  636.         begin
  637.             ToggleOpponentArrow;
  638.             tileToggle := 1;
  639.             tileLit := 0;
  640.             with ball do
  641.                 begin
  642.                     opponent.velX := opponent.velX + velX * 2 div 3;
  643.                     opponent.velZ := opponent.velZ + velZ * 2 div 3;
  644.                     velX := opponent.velX;
  645.                     velZ := opponent.velZ;
  646.                     ballJustHit := TRUE;
  647.                     mode := opponentHasBall;
  648.                     timeKeeper := 1;
  649.                     opponent.carryMode := carrying;
  650.                     CopyBits(offVirginMap, offLoadMap, oldDest, oldDest, srcCopy, nil);
  651.                     CopyBits(offVirginMap, mainWndo^.portBits, oldDest, oldDest, srcCopy, wholeRgn);
  652.                     if (soundArray[5]) then
  653.                         DoTheSound(ballCatches[whichOpponent], highPriority);
  654.                 end;
  655.         end;
  656.  
  657. {-------------------------}
  658.  
  659.         procedure PlayerCollides;
  660.             var
  661.                 tempX, tempZ: LongInt;
  662.         begin
  663.             if (player.timeKeeper < 0) then
  664.                 Exit(PlayerCollides);
  665.             lastTouchingBall := playerHasBall;
  666.             if (ballJustHit) then
  667.                 Exit(PlayerCollides);
  668.             if ((button) or (autoPickUp)) then
  669.                 PlayerCapture
  670.             else
  671.                 with ball do
  672.                     begin
  673.                         if (soundArray[5]) then
  674.                             DoTheSound('ricochet', lowPriority);
  675.                         tempX := velX;
  676.                         tempZ := velZ;
  677.                         velX := player.velX * 3 div 2;
  678.                         velZ := player.velZ * 3 div 2;
  679.                         player.velX := tempX * 2 div 3;
  680.                         player.velZ := tempZ * 2 div 3;
  681.                         ballJustHit := TRUE;
  682.                     end;
  683.         end;
  684.  
  685. {-------------------------}
  686.  
  687.         procedure OpponentCollides;
  688.             var
  689.                 tempX, tempZ: LongInt;
  690.         begin
  691.             if ((whichGame <= practiceWBall) or (opponent.timeKeeper < 0)) then
  692.                 Exit(OpponentCollides);
  693.             lastTouchingBall := opponentHasBall;
  694.             if (ballJustHit) then
  695.                 Exit(OpponentCollides);
  696.             if (opponentWants) then
  697.                 OpponentCapture
  698.             else
  699.                 with ball do
  700.                     begin
  701.                         if (soundArray[5]) then
  702.                             DoTheSound('ricochet', lowPriority);
  703.                         tempX := velX;
  704.                         tempZ := velZ;
  705.                         velX := opponent.velX * 3 div 2;
  706.                         velZ := opponent.velZ * 3 div 2;
  707.                         opponent.velX := tempX * 2 div 3;
  708.                         opponent.velZ := tempZ * 2 div 3;
  709.                         ballJustHit := TRUE;
  710.                     end;
  711.         end;
  712.  
  713. {-------------------------}
  714.  
  715.         procedure PlayerCarriesBall;
  716.             var
  717.                 field1, field2: Integer;
  718.                 tempX, tempZ: LongInt;
  719.         begin
  720.             with ball do
  721.                 if (clicked) then
  722.                     begin
  723.                         ResetArrows;
  724.                         ballJustHit := TRUE;
  725.                         mode := nooneHasBall;
  726.                         player.carryMode := notCarrying;
  727.                         timeKeeper := 0;
  728.                         tempX := velX;
  729.                         tempZ := velZ;
  730.                         velX := player.velX * 3 div 2;
  731.                         velZ := player.velZ * 3 div 2;
  732.                         player.velX := player.velX div 2;
  733.                         player.velZ := player.velZ div 2;
  734.                         posX := posX + velX;
  735.                         posZ := posZ + velZ;
  736.                         screenH := centerH + posX div 100;
  737.                         field1 := ABS(posX div 300);
  738.                         field2 := posZ div 300;
  739.                         if ((field1 < 81) and (ABS(field2) < 81)) then
  740.                             begin
  741.                                 HLock(Handle(vertTable));
  742.                                 screenV := vertTable^^.data[field1, field2] + 20;
  743.                                 HUnlock(Handle(vertTable));
  744.                             end
  745.                         else
  746.                             BallOutOfArena;
  747.                         if (screenV < 0) then
  748.                             BallOutOfArena;
  749.                         SetRect(dest, screenH - 6, screenV - 12, screenH + 6, screenV);
  750.                         oldDest := dest;
  751.                         if (soundArray[5]) then
  752.                             DoTheSound('ballDrop', lowPriority);
  753.                     end
  754.                 else
  755.                     begin
  756.                         velX := player.velX;
  757.                         velZ := player.velZ;
  758.                         posX := player.posX;
  759.                         posZ := player.posZ;
  760.                         SetRect(dest, 1, 30, 1, 30);
  761.                         oldDest := dest;
  762.                         timeKeeper := timeKeeper + 1;
  763.                     end;
  764.         end;
  765.  
  766. {-------------------------}
  767.  
  768.         procedure OpponentCarriesBall;
  769.             var
  770.                 field1, field2: Integer;
  771.                 tempX, tempZ: LongInt;
  772.         begin
  773.             with ball do
  774.                 if (opponentDropping) then
  775.                     begin
  776.                         ResetArrows;
  777.                         opponentDropping := FALSE;
  778.                         ballJustHit := TRUE;
  779.                         mode := nooneHasBall;
  780.                         opponent.carryMode := notCarrying;
  781.                         timeKeeper := 0;
  782.                         tempX := velX;
  783.                         tempZ := velZ;
  784.                         velX := opponent.velX * 3 div 2;
  785.                         velZ := opponent.velZ * 3 div 2;
  786.                         opponent.velX := opponent.velX div 2;
  787.                         opponent.velZ := opponent.velZ div 2;
  788.                         posX := posX + velX;
  789.                         posZ := posZ + velZ;
  790.                         screenH := centerH + posX div 100;
  791.                         field1 := ABS(posX div 300);
  792.                         field2 := posZ div 300;
  793.                         if ((field1 < 81) and (ABS(field2) < 81)) then
  794.                             begin
  795.                                 HLock(Handle(vertTable));
  796.                                 screenV := vertTable^^.data[field1, field2] + 20;
  797.                                 HUnlock(Handle(vertTable));
  798.                             end
  799.                         else
  800.                             BallOutOfArena;
  801.                         if (screenV < 0) then
  802.                             BallOutOfArena;
  803.                         SetRect(dest, screenH - 6, screenV - 12, screenH + 6, screenV);
  804.                         oldDest := dest;
  805.                         if (soundArray[5]) then
  806.                             DoTheSound('ballDrop', lowPriority);
  807.                     end
  808.                 else
  809.                     begin
  810.                         velX := opponent.velX;
  811.                         velZ := opponent.velZ;
  812.                         posX := opponent.posX;
  813.                         posZ := opponent.posZ;
  814.                         SetRect(dest, 1, 30, 1, 30);
  815.                         oldDest := dest;
  816.                         timeKeeper := timeKeeper + 1;
  817.                     end;
  818.         end;
  819.  
  820. {-------------------------}
  821.  
  822.         procedure BallRolling;
  823.             var
  824.                 field1, field2, forceX, forceZ: Integer;
  825.         begin
  826.             with ball do
  827.                 begin
  828.                     if ((ABS(posX - player.posX) < 2000) and (ABS(posZ - player.posZ) < 2000)) then
  829.                         PlayerCollides
  830.                     else
  831.                         begin
  832.                             if ((ABS(posX - opponent.posX) < 2000) and (ABS(posZ - opponent.posZ) < 2000)) then
  833.                                 OpponentCollides
  834.                             else
  835.                                 ballJustHit := FALSE;
  836.                         end;
  837.  
  838.                     if ((ABS(posX) <= 24000) and (ABS(posZ) <= 24000)) then
  839.                         begin
  840.                             forceX := forceTable[posX div 1000, posZ div 1000, 0];
  841.                             forceZ := forceTable[posX div 1000, posZ div 1000, 1];
  842.                             if ((forceX = 10000) or (forceX = 11000)) then
  843.                                 begin
  844.                                     if ((forceZ = 20000) or (forceZ = 30000)) then
  845.                                         begin
  846.                                             ResetArrows;
  847.                                             DoAScore(forceZ);
  848.                                         end
  849.                                     else
  850.                                         begin
  851.                                             if forceX = 10000 then
  852.                                                 begin
  853.                                                     if ((velZ < 0) and (velX < 0)) then
  854.                                                         begin
  855.                                                             if (soundArray[5]) then
  856.                                                                 DoTheSound('ricochet', lowPriority);
  857.                                                             forceX := velX * 2 div 3;
  858.                                                             velX := -velZ * 2 div 3;
  859.                                                             velZ := -forceX;
  860.                                                         end;
  861.                                                     if ((-velZ > velX) and (velZ < 0) and (velX > 0)) then
  862.                                                         begin
  863.                                                             if (soundArray[5]) then
  864.                                                                 DoTheSound('ricochet', lowPriority);
  865.                                                             forceX := velX * 2 div 3;
  866.                                                             velX := -velZ * 2 div 3;
  867.                                                             velZ := -forceX;
  868.                                                         end;
  869.                                                     if ((-velX > velZ) and (velZ > 0) and (velX < 0)) then
  870.                                                         begin
  871.                                                             if (soundArray[5]) then
  872.                                                                 DoTheSound('ricochet', lowPriority);
  873.                                                             forceX := velX * 2 div 3;
  874.                                                             velX := -velZ * 2 div 3;
  875.                                                             velZ := -forceX;
  876.                                                         end;
  877.                                                 end
  878.                                             else
  879.                                                 begin
  880.                                                     if ((velZ < 0) and (velX > 0)) then
  881.                                                         begin
  882.                                                             if (soundArray[5]) then
  883.                                                                 DoTheSound('ricochet', lowPriority);
  884.                                                             forceX := velX * 2 div 3;
  885.                                                             velX := velZ * 2 div 3;
  886.                                                             velZ := forceX;
  887.                                                         end;
  888.                                                     if ((velZ < velX) and (velZ < 0) and (velX < 0)) then
  889.                                                         begin
  890.                                                             if (soundArray[5]) then
  891.                                                                 DoTheSound('ricochet', lowPriority);
  892.                                                             forceX := velX * 2 div 3;
  893.                                                             velX := velZ * 2 div 3;
  894.                                                             velZ := forceX;
  895.                                                         end;
  896.                                                     if ((velX > velZ) and (velZ > 0) and (velX > 0)) then
  897.                                                         begin
  898.                                                             if (soundArray[5]) then
  899.                                                                 DoTheSound('ricochet', lowPriority);
  900.                                                             forceX := velX * 2 div 3;
  901.                                                             velX := velZ * 2 div 3;
  902.                                                             velZ := forceX;
  903.                                                         end;
  904.                                                 end;
  905.                                         end;
  906.                                 end
  907.                             else if (forceX < 10000) then
  908.                                 begin
  909.                                     velX := velX * 49 div 50 + forceX;
  910.                                     velZ := velZ * 49 div 50 + forceZ;
  911.                                 end
  912.                         end
  913.                     else
  914.                         begin
  915.                         end;
  916.                     posX := posX + velX;
  917.                     posZ := posZ + velZ;
  918.                     screenH := centerH + posX div 100;
  919.                     field1 := ABS(posX div 300);
  920.                     field2 := posZ div 300;
  921.                     if ((field1 < 81) and (ABS(field2) < 81)) then
  922.                         begin
  923.                             HLock(Handle(vertTable));
  924.                             screenV := vertTable^^.data[field1, field2] + 20;
  925.                             HUnlock(Handle(vertTable));
  926.                         end
  927.                     else
  928.                         BallOutOfArena;
  929.                     if (screenV < 0) then
  930.                         BallOutOfArena;
  931.                     SetRect(dest, screenH - 6, screenV - 12, screenH + 6, screenV);
  932.                 end;
  933.         end;
  934.  
  935. {-------------------------}
  936.  
  937.     begin
  938.         with ball do
  939.             begin
  940.                 if (mode = playerHasBall) then
  941.                     PlayerCarriesBall
  942.                 else if (mode = opponentHasBall) then
  943.                     OpponentCarriesBall
  944.                 else
  945.                     BallRolling;
  946.                 clicked := FALSE;
  947.                 if (timeKeeper = 250) then
  948.                     DoTheSound('holding', highPriority);
  949.                 if (timeKeeper > 300) then
  950.                     begin
  951.                         ResetArrows;
  952.                         DoHolding;
  953.                     end;
  954.             end;
  955.     end;
  956.  
  957. {=================================}
  958.  
  959.     procedure BallInTransit;
  960.     begin
  961.         with ball do
  962.             begin
  963.                 timeKeeper := timeKeeper + 1;
  964.                 if ((timeKeeper = -10) and (soundArray[3])) then
  965.                     DoTheSound('ballShot', highPriority);
  966.                 if (timeKeeper = 0) then
  967.                     begin
  968.                         with ball do
  969.                             begin
  970.                                 velX := -2500;
  971.                                 velZ := 0;
  972.                                 posX := 300;
  973.                                 posZ := -20500;
  974.                                 screenH := centerH + posX div 100;
  975.                                 HLock(Handle(vertTable));
  976.                                 screenV := vertTable^^.data[ABS(posX div 300), posZ div 300] + 20;
  977.                                 HUnlock(Handle(vertTable));
  978.                                 SetRect(dest, screenH - 6, screenV - 12, screenH + 6, screenV);
  979.                                 oldDest := dest;
  980.                             end;
  981.                         NewBallPosition;
  982.                     end;
  983.             end;
  984.     end;
  985.  
  986. {=================================}
  987.  
  988. end.